
// This program demonstrates how to get character outlines and plot them.

// In this example, the characters each have different colors, fonts,
//   rotation, and filltype. You may substitute any fonts on your computer. 
// The "baseline" curves, since each character is rotated more 
//   than the previous one, and the next offset depends on the rotation.

INCLUDE "standard_colors.txt"	// (make sure you have downloaded this file)
DEGREES
DIM array (10,2)
next_offset_x = 100
next_offset_y = 100
rotation_angle = 45
stretch = 0  			// 0=normal. Try other values

GRAPH EQUALSCALES
GRAPH INCLUDEXAXIS=0, INCLUDEYAXIS=0 
GRAPH WIDTH=6, HEIGHT=3, NOAXES

SHAPE FONT = "Old English Text MT"
SHAPE CHARACTERS = "T"
SHAPE LEFT = next_offset_x,   RIGHT = next_offset_x + stretch
SHAPE BOTTOM = next_offset_y, TOP = next_offset_y + 100
SHAPE BOLD = 100, ITALIC = 0
SHAPE ROTATE = rotation_angle
SHAPE POLYPOINTS = array
SHAPE CHAROUTLINE
// Now array has new dimensions, and contains the outline.

SHAPE ROTATE = 0
SHAPE FILLTYPE = solid, FILLCOLOR = red
SHAPE LINECOLOR = black
GOSUB 800			// Draw the outline on the screen


SHAPE FONT = "Arial Black"
SHAPE CHARACTERS = "e"
SHAPE LEFT = next_offset_x,   RIGHT = next_offset_x + stretch
SHAPE BOTTOM = next_offset_y, TOP = next_offset_y + 100
SHAPE BOLD = 100, ITALIC = 0
SHAPE ROTATE = rotation_angle-30
SHAPE CHAROUTLINE

SHAPE ROTATE = 0
SHAPE FILLTYPE = hatch, HATCH = DIAGCROSS, FILLCOLOR = green
SHAPE LINECOLOR = black
GOSUB 800			// Draw the outline on the screen


SHAPE FONT = "Times New Roman"
SHAPE CHARACTERS = "x"
SHAPE LEFT = next_offset_x,   RIGHT = next_offset_x + stretch
SHAPE BOTTOM = next_offset_y, TOP = next_offset_y + 100
SHAPE BOLD = 100, ITALIC = 1		// make this letter italic
SHAPE ROTATE = rotation_angle-60
SHAPE CHAROUTLINE

SHAPE ROTATE = 0
SHAPE FILLTYPE = none
SHAPE LINECOLOR = black
GOSUB 800			// Draw the outline on the screen

SHAPE FONT = "Comic Sans MS Bold"
SHAPE CHARACTERS = "t"
SHAPE LEFT = next_offset_x,   RIGHT = next_offset_x + stretch
SHAPE BOTTOM = next_offset_y, TOP = next_offset_y + 100
SHAPE BOLD = 100, ITALIC = 0
SHAPE ROTATE = rotation_angle-90
SHAPE CHAROUTLINE

SHAPE ROTATE = 0
SHAPE FILLTYPE = solid, FILLCOLOR = gold
SHAPE LINECOLOR = black
GOSUB 800			// Draw the outline on the screen

END

//---------------------------------------------------------
// This subroutine draws the outline described in the array
//---------------------------------------------------------
800
SHAPE BEGINPATH
// First point is (x=number of contours, y=0)
i = 0
num_contours = array(i, 0)
i = i + 1
WHILE num_contours > 0  

  // Next point is (x=number of curves in this contour,y=0)
  num_curves = array(i,0)
  i = i + 1

  // next point is start point for this contour
  start_x = array(i,0): start_y = array(i,1)
  current_x = start_x:  current_y = start_y
  i = i + 1

  WHILE num_curves > 0
    // next point is (x=number of points in curve, y=type)
    num_points = array(i,0)
    type = array (i,1)
    i = i + 1

    IF type = 1 THEN GOTO 1000 ELSE GOTO 2000
1000 // polyline
    // We will do this polyline as a series if lines to avoid
    // having to re-allocate the polypoints array each time
    WHILE num_points > 0
      next_x = array(i,0)
      next_y = array(i,1)
      i = i + 1
      SHAPE LINESTART = (current_x, current_y)
      SHAPE LINEEND   = (next_x, next_y), LINE
      current_x = next_x: current_y = next_y
      num_points = num_points - 1
    WEND // end of polyline
    GOTO 3000

2000 // Bezier
    while num_points > 0
      ctlpt1_x = array(i,0): ctlpt1_y = array(i,1)
      i = i + 1
      ctlpt2_x = array(i,0): ctlpt2_y = array(i,1)
      i = i + 1
      next_x = array(i,0): next_y = array(i,1)
      i = i + 1
      SHAPE LINESTART = (current_x, current_y)
      SHAPE LINEEND   = (next_x, next_y)
      SHAPE CTLPT1    = (ctlpt1_x, ctlpt1_y)
      SHAPE CTLPT2    = (ctlpt2_x, ctlpt2_y)
      SHAPE BEZIER
      current_x  = next_x: current_y = next_y
      num_points = num_points - 3
    WEND	// end of Bezier

3000
    num_curves = num_curves - 1
  WEND  // end of contour
  SHAPE CLOSEFIGURE

  num_contours = num_contours - 1
WEND // end of shape

SHAPE ENDPATH
SHAPE STROKEFILL

i = array(0,1) // index to metrics
offset_x = array (i, 0)
offset_y = array (i, 1)
next_offset_x = offset_x
next_offset_y = offset_y

RETURN